package com.helen.adapter;

import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.helen.entity.ProductEntity;
import com.helen.shopping.R;
import com.helen.utils.ImageLoadUtil;
import com.helen.utils.MyLog;

import java.util.List;


/**
 * Created by yang on 2018/4/23.
 */

public class ProductAdapter extends BaseQuickAdapter<ProductEntity, BaseViewHolder> {

    public ProductAdapter(int layoutResId, List<ProductEntity> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(final BaseViewHolder helper, final ProductEntity item) {
        try {
            ImageView imgProduct = (ImageView) helper.getView(R.id.img_product);
            TextView tvTitle = (TextView) helper.getView(R.id.tv_title);
            TextView tvCount = (TextView) helper.getView(R.id.tv_count);
            TextView tvPrice = (TextView) helper.getView(R.id.tv_price);
            TextView tvPaidPeople = (TextView) helper.getView(R.id.tv_paid_people);
            if (item.getImgs() != null && item.getImgs().size() > 0) {
                ImageLoadUtil.displayImage(mContext, imgProduct, item.getImgs().get(0).getUrl(), R.mipmap.app_logo, R.mipmap.app_logo);
            }
            tvTitle.setText(item.getName());
            String unit = item.getUnit();
            if (item.getCount() != -1) {
                tvCount.setText("剩余: " + item.getCount() + unit);
            } else {
                tvCount.setText("剩余9999+");
            }


            if (!TextUtils.isEmpty(unit)) {
                if (item.getDiscountprice() != 0) {
                    tvPrice.setText(item.getDiscountprice() + "/" + unit);
                }else {
                    tvPrice.setText(item.getCostprice() + "/" + unit);
                }

            }else {
                if (item.getDiscountprice() != 0) {
                    tvPrice.setText(item.getDiscountprice()+"");
                }else {
                    tvPrice.setText(item.getCostprice()+"");
                }

            }

            tvPaidPeople.setText(item.getPaycount() + "人付款");
        } catch (Exception e) {
            MyLog.e("yang", "商品列表异常" + e.toString());
        }


    }


}
